import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_base_app/config/app_colors.dart';
import 'package:flutter_base_app/config/theme.dart';
import 'package:flutter_base_app/widgets/image/svg_widget.dart';

///Action 块按钮
class ActionItemWidget extends StatelessWidget {
  final String title;
  final String icon;
  final double? height;
  final double? width;
  final double? iconHeight;
  final double? iconWidth;
  final double elevation;
  final Color? color;

  ///hover 颜色是否改变
  final bool hoverChange;

  final Function? onClick;


  ActionItemWidget(
      this.title,
      this.icon, {
        super.key,
        this.width = 150,
        this.height = 60,
        this.iconWidth,
        this.iconHeight,
        this.elevation = 0,
        this.color,
        this.hoverChange = true,
        this.onClick,
      });

  final isHover = false.obs;

  @override
  Widget build(BuildContext context) {
    final bgColor = color ?? ColorsApp.page_background;
    return Material(
      elevation: elevation,
      borderRadius: BorderRadius.circular(10), // 匹配 BoxDecoration 的圆角半径
      color: bgColor, // 设置 Material 的背景色
      child: InkWell(
        onTap: () {
          onClick?.call();
        },
        onHover: (hover) {
          if (hoverChange) {
            isHover.value = hover;
          }
        },
        borderRadius: BorderRadius.circular(10),
        splashColor: Colors.black.withValues(alpha: 0.2),
        child: Obx(() => Container(
          width: width,
          height: height,
          decoration: BoxDecoration(
              border: Border.all(
                color: isHover.value ? primaryColor : ColorsApp.dividerColor,
                width: 1,
              ),
              borderRadius: BorderRadius.circular(10)),
          padding: const EdgeInsets.symmetric(horizontal: 10),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            children: _buildWidgetList(context),
          ),
        )),
      ),
    );
  }

  List<Widget> _buildWidgetList(BuildContext context) {
    return [
      SvgWidget(
        icon,
        colorFilter: (isHover.value ? primaryColor : ColorsApp.black).toColorFilter(),
        width: iconWidth,
        height: iconHeight,
      ),
      const SizedBox(
        width: 5,
        height: 5,
      ),
      Text(
        title,
        style: TextStyle(color: isHover.value ? primaryColor : ColorsApp.black, fontSize: 16),
      )
    ];
  }
}
